import java.util.concurrent.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-04-15
 * Time: 21:57
 */
/*使用ThreadPoolExecutor创建一个忽略最新任务的线程池，创建规则：

1.核心线程数为5

2.最大线程数为10

3.任务队列为100

4.拒绝策略为忽略最新任务*/
public class test_3 {
    //public static final Object lock = new Object();
    public static void main(String[] args) {
        BlockingQueue<Runnable> blockingQueue=new ArrayBlockingQueue<>(2);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1,4,
                1000, TimeUnit.MICROSECONDS,blockingQueue,Executors.defaultThreadFactory(),
        new ThreadPoolExecutor.DiscardOldestPolicy());
        for (int i = 0; i < 10; i++) {
            threadPoolExecutor.submit(()->
                        System.out.println("你好")
                );
            //                    try {
//                        System.out.println(Thread.currentThread().getName());
//                    } catch (InterruptedException e) {
//                        System.out.println("结束了");
//                        throw new RuntimeException(e);
//                    }
        }
    }
}
